/* Copyright (c) 2004-2024 peigen.info. All rights reserved. */

package info.peigen.hotpot.manage.core.service;

import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceInvoke;
import info.peigen.hotpot.manage.core.service.facade.UserServiceFacade;
import info.peigen.hotpot.manage.core.service.order.UserCreateOrder;
import info.peigen.hotpot.manage.core.service.order.UserEditOrder;
import info.peigen.hotpot.manage.core.service.result.UserCreateResult;
import info.peigen.hotpot.manage.core.service.result.UserEditResult;
import org.noear.solon.annotation.Component;

/**
 * <b>(UserService)</b>
 * "用户" 服务实现
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2024-06-28
 */
@SuppressWarnings({"unused", "rawtypes"})
@Component
public class UserService extends AbstractHotpotManageService implements UserServiceFacade {

    @Override
    public UserCreateResult create(UserCreateOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order)
                .result(new UserCreateResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addPreProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(userCreatePasswordCheckProcessor);
            }

            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(userCreateProcessor, userCreateMobileOrEmailProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(userStoreProcessor, userCreateResultProcessor);
            }
        });
        return (UserCreateResult) serviceContext.getResult();
    }

    @Override
    public UserEditResult edit(UserEditOrder order) {
        ProcessorServiceContext serviceContext = ProcessorServiceContext.builder().order(order)
                .result(new UserEditResult()).build();
        execute(serviceContext, new ProcessorServiceInvoke() {
            @Override
            public void addPreProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(userActiveProcessor, userEditCheckProcessor);
            }

            @Override
            public void addProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(userEditProcessor, userEditBusinessProcessor);
            }

            @Override
            public void addPostProcessor(ProcessorServiceContext serviceContext) {
                serviceContext.addProcessors(userStoreProcessor, userEditResultProcessor);
            }
        });
        return (UserEditResult) serviceContext.getResult();
    }
}